﻿using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace XNAFight.Engine.Inputs
{
    public class SpecificMenuInputInterpreter
    {
        #region CHAMPS

        // peripherique utilisé 
        Controler controler;

        #endregion

        #region INITIALISATION

        public SpecificMenuInputInterpreter(Controler _controler)
        {
            controler = _controler;
        }

        #endregion

        #region METHODES

        // Validation d'une entrée
        public bool isMenuItemSelected()
        {
            if (controler.Type == InputType.Keyboard)
                return 
                    InputState.isNewKeyPressed(Keys.Space) ||
                    InputState.isNewKeyPressed(Keys.Enter);
            else 
                return 
                   InputState.isNewButtonPressed(Buttons.Start, controler.Index) ||
                   InputState.isNewButtonPressed(Buttons.A, controler.Index);
        }
        
        // Annulation
        public bool isMenuCanceled()
        {
            if (controler.Type == InputType.Keyboard)
                return InputState.isNewKeyPressed(Keys.Escape);
            else
                return
                   InputState.isNewButtonPressed(Buttons.Back, controler.Index) ||
                   InputState.isNewButtonPressed(Buttons.B, controler.Index);
        }

        // Selection vers le haut
        public bool isMenuUp()
        {
            if (controler.Type == InputType.Keyboard)
                return InputState.isNewKeyPressed(Keys.Up);
            else
                return
                   InputState.isNewButtonPressed(Buttons.DPadUp, controler.Index) ||
                   InputState.isLeftStickUpped();
        }
        
        // Selection vers le bas
        public bool isMenuDown()
        {
            if (controler.Type == InputType.Keyboard)
                return InputState.isNewKeyPressed(Keys.Down);
            else
                return
                   InputState.isNewButtonPressed(Buttons.DPadDown, controler.Index) ||
                   InputState.isLeftStickDowned();
        }

        // Selection vers la droite
        public bool isMenuRight()
        {
            if (controler.Type == InputType.Keyboard)
                return InputState.isNewKeyPressed(Keys.Right);
            else
                return
                   InputState.isNewButtonPressed(Buttons.DPadRight, controler.Index) ||
                   InputState.isLeftStickOnRight();
        }
        
        // Selection vers la gauche
        public bool isMenuLeft()
        {
            if (controler.Type == InputType.Keyboard)
                return InputState.isNewKeyPressed(Keys.Left);
            else
                return
                   InputState.isNewButtonPressed(Buttons.DPadLeft, controler.Index) ||
                   InputState.isLeftStickOnLeft();
        }

        // Ouverture du menu de debug
        public bool isDebugPressed()
        {
            if (controler.Type == InputType.Keyboard)
                return InputState.isNewKeyPressed(Keys.F1);
            else
                return InputState.isNewButtonPressed(Buttons.RightStick, controler.Index);
        }
        #endregion

    }
}
